<?php
session_start();

include_once("../../Misc.php");
include_once("../../classCol/UID.php");
include_once("../../classCol/classOracleDb.php");
include_once("../../helpers/CHtml.php");
include_once("../../helpers/Composer.php");
include_once("../../helpers/ComposerSourceDb.php");
include_once("../../models/GlobalFetchers.php");
include_once("../models/fetchers.php");

$GHtml      = new CGHtml;
$CLFetchers = new CLFetchers;
$CFetchers  = new GlobalFetchers;

$SourceDb   = new Composer;
$SourceDb   = $SourceDb->init("db");

$SourceDb->add("srcDbWarehouse",  "WHS_".$_POST["whs"]);
$SourceDb->add("srcDbMstWhs",     "MST_WAREHOUSE");
$SourceDb->add("srcDbModel",      "MST_MODEL");
$SourceDb->add("srcDbSN",         "SN_SUB_DTl");

$Db = new oracleDb;
$Db->init($_SESSION["ORCL"],
          $_SESSION["OPASS"],
          $_SESSION["SID"],
          _NO_COMMENT);

if($Db->connect()){

  $CFetchers->fetchWhsBalance($Db,
                              $_POST["modelId"],
                              $_POST["UNIT"],
                              $SourceDb->fetchValue("srcDbWarehouse"),
                              $nBal,
                              $whsQty);

  /**
   * if its lower equal than qty then we are good
   */
  if($_POST["qty"] <= $whsQty){

    echo  true;
  }else{

    echo _RET_NULL;
  }

  $Db->dc();
}else{

  echo _CONN_ERROR;
}

?>